<%--
  Created by IntelliJ IDEA.
  User: 武露斌
  Date: 2021/10/20
  Time: 11:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-1.8.2.min.js"></script>
    <script src="../../js/fileupload.js"></script>
    <link rel="stylesheet" href="../../css/css.css">
    <link rel="stylesheet" href="../../css/img.css">
</head>
<body>

<form>
    顾客姓名：<input type="text" name="uname"><br>
    联系电话：<input type="text" name="ctel"><br>
    是否为会员：
    <input type="radio" name="umember" value="1">是
    <input type="radio" name="umember" value="2">否<br>
    拍摄地点：
    <div name="aa">

    </div><br>
    地址：
    <select name="sheng" onchange="sheng2()">
        <option value="">请选择省份</option>
    </select>
    <select name="shi" onchange="shi2()">
        <option value="">请选择市</option>
    </select>
    <select name="xian">
        <option value="">请选择县</option>
    </select>

</form>
<input type="button" value="添加" onclick="add()">

</body>
</html>

<script>

    $.post(
        "listshoot.do",
        function (data) {
            for (var i = 0; i <data.length ; i++) {
                $("[name='aa']").append('<input type="checkbox" name="sids" value="'+data[i].sid+'">'+data[i].sname)
            }
        }
    )


    $.post(
        "listcity.do",
        {"pid":0},
        function (data) {
            for (var i = 0; i <data.length ; i++) {
                $("[name='sheng']").append('<option value="'+data[i].id+'">'+data[i].name+'</option>')
            }
        }
    )

    function sheng2() {
      var pid= $("[name='sheng']").val()

        $("[name='shi']").empty()
        $("[name='shi']").append('<option value="">请选择市</option>')
        $("[name='xian']").empty()
        $("[name='xian']").append('<option value="">请选择县</option>')

        $.post(
            "listcity.do",
            {"pid":pid},
            function (data) {
                for (var i = 0; i <data.length ; i++) {
                    $("[name='shi']").append('<option value="'+data[i].id+'">'+data[i].name+'</option>')
                }
            }
        )

    }

    function shi2() {
        var pid= $("[name='shi']").val()

        $("[name='xian']").empty()
        $("[name='xian']").append('<option value="">请选择县</option>')

        $.post(
            "listcity.do",
            {"pid":pid},
            function (data) {
                for (var i = 0; i <data.length ; i++) {
                    $("[name='xian']").append('<option value="'+data[i].id+'">'+data[i].name+'</option>')
                }
            }
        )
    }

    function add() {

        if ($("[name='uname']").val().length==0){
            alert("用户名不能为空")
            return false;
        }

        var ctel=$("[name='ctel']").val()

        var ctels = /^\d{11}$/;
        if (!ctels.test(ctel)){
            alert("电话号码不能为空！请输入正确的格式")
            return false
        }else{
            var formData = new FormData($("form")[0]);
            $.ajax({
                url:"add.do",
                data:formData,
                type:"post",
                dataType:"json",
                success:function (data) {
                    if (data>0){
                        alert("添加成功")
                        location="list.do"
                    }else{
                        alert("添加失败")
                    }
                },processData:false,contentType:false
            })
        }




    }

</script>



















